Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
How to use multiple word in "startsWith"
if (message.content.startsWith('let', 'Let')){/do something/})

I want bot work when user type "let" or "Let", but it can just work when "let" typed How to fix this? Thanks for helping

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could use regular expressions here:

var terms = ["let", "Let"];
var regex = new RegExp("^(?:" + terms.join("|") + ")\\b");
var inputs = ["Let it be!", "let it be!", "Green Eggs and Ham"];
for (var i=0; i < inputs.length; ++i) {
    if (regex.test(inputs[i])) {
        console.log("MATCH    => " + inputs[i]);
    }
    else {
        console.log("NO MATCH => " + inputs[i]);
    }
}

To be clear, we are using test() with the regex pattern:

^(?:let|Let)\b

You may add more terms to the above alternation as needed.

about 4 years ago · Juan Pablo Isaza Report

0

To keep things flexible you could keep an array of words you want to check, and then use some to check to see if any of those words are at the beginning of the content string.

const words = ['let', 'Let', 'Bob'];

const message1 = { content: 'let' };
const message2 = { content: 'notlet' };
const message3 = { content: 'Let' };
const message4 = { content: 'Bob' };

function startsWith(message) {
  return words.some(word => {
    return message.content.startsWith(word);
  });
}

console.log(startsWith(message1));
console.log(startsWith(message2));
console.log(startsWith(message3));
console.log(startsWith(message4));

about 4 years ago · Juan Pablo Isaza Report

0

I believe you are looking for case insensitive match. In that case following can work assuming your message.content is a string or object.
Here we collect user typed string in userTypedThis variable.

if (message.content.toString().toLowerCase().startsWith(
   userTypedThis.toString().toLowerCase())
){/do something/})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!